31 Mayıs 2018 Perşembe

JAX-WS @WebService Anostasyonu

Giriş
Şu satırı dahil ederiz.
import javax.jws.WebService;
@WebMethod,@WebParam,@ WebResult gibi anotasyonlarla beraber kullanıldığı için şu satırı dahil ederiz.
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
Kullanım
Şöyle yaparız
import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public class Hello {
  private final String message = "Hello, ";

  public Hello() {
  }

  @WebMethod
  public String sayHello(String name) {
    return message + name + ".";
  }
}
Standalone Deployment
Endpoint.publish metodu kullanılır.

endPointInterface Alanı
Şöyle yaparız.
@WebService(endpointInterface = "com.enterprise.ws.WebServiceInterface")
public class WebServiceImpl implements WebServiceInterface {

  @Resource
  WebServiceContext webServiceContext;

  @Override
  public String getHelloWorldAsString(String str) {
    ...
    return "...";
   
  }
}
name Alanı
Şöyle yaparız.
@WebService(targetNamespace = "asd:asd", name = "MyServiceInterface")
@XmlSeeAlso({asd.asd.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface MyServiceInterface {

    @WebMethod(operationName = "Operation", action = "asd:asd:#Operation")
    @WebResult(name = "OperationResponse", targetNamespace = "asd:asd",
      partName = "OperationResponseBody")
    public asd.asd.OperationResponseType operation(
        @WebParam(partName = "OperationBody",
                  name = "DateSinceStart",
                  targetNamespace = "asd:asd")
        @XmlJavaTypeAdapter(Adapter1.class)
        java.time.LocalDateTime operationBody
    );
}
serviceName Alanı
Örnek
Şöyle yaparız.
@WebService(serviceName="MyWebService",
            portName="MyWebServicePort",
            endpointInterface="com.abc.MyWebService",
            targetNamespace="http://abc.com")
public class MyWebService implements MyWebServiceInterface {...}
Örnek
Şöyle yaparız
import com.tutorialspoint.entity.Book;
import java.util.List;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
@WebService(serviceName="LibraryService")
public class LibraryPersistentBean implements LibraryPersistentBeanRemote {
    
  public LibraryPersistentBean() {
  }

  @PersistenceContext(unitName="EjbComponentPU")
  private EntityManager entityManager;         

  public void addBook(Book book) {
    entityManager.persist(book);
      
  
  @WebMethod(operationName="getBooks")
  public List <Book> getBooks() {
    return entityManager.createQuery("From Book").getResultList();
  }
}
targetNamespace Alanı
Şöyle yaparız
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;


@WebService(targetNamespace = "http://aa.com/FareFilingService/", name = "FareFiling")
@XmlSeeAlso({com.aa.farefilling.to.ObjectFactory.class, ObjectFactory.class})
public interface FareFiling {

  @WebMethod
  @RequestWrapper(localName = "fileFare", 
    targetNamespace = "http://aa.com/FareFilingService/",
    className = "com.aa.farefilingservice.FileFare")
  @ResponseWrapper(localName = "fileFareResponse", 
    targetNamespace = "http://aa.com/FareFilingService/",
    className = "com.aa.farefilingservice.FileFareResponse")
  @WebResult(name = "fareResponse", targetNamespace = "")
  public com.aa.farefilling.to.FareResponse[] fileFare(
    @WebParam(name = "fareData", targetNamespace = "")
    com.aa.farefilling.to.FareData fareData
  ) throws FileFareFault;
}




Hiç yorum yok:

Yorum Gönder