2012-08-09 4 views
1

내가 작업중인 프로젝트의 웹 서비스에 액세스하려고합니다. JAX-WS를 사용 중이며 weblogic에 배치되었습니다. 내가 WS에 액세스하려고 해요 때, 나는 다음과 같은 예외를 얻을 :javax.xml.ws.WebServiceException : WSDL에 액세스하지 못했습니다. 응답 : '401 : Unauthorized'

javax.portlet.PortletException: javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://xxx.xxxx.ro:40000/idm/ws/cup?wsdl. It failed with: 
Response: '401: Unauthorized' for url: 'http://xxx.xxxx.ro:40000/idm/ws/cup?wsdl'. 
at com.bea.portlet.container.PortletStub.processAction(PortletStub.java:346) 
at com.bea.portlet.container.AppContainer.invokeProcessAction(AppContainer.java:678) 
........ 

나는 문제에 관한 글을 많이 읽어와 나는 인증의 다른 유형을 시도했다. 다른 사용법에서 BindingProvider, basicHTTPAuth를 사용하려고 시도했지만 HostnameVerifier 등을 사용하지 않도록 설정했지만 결과는 여전히 남았습니다. 다음은

는, 내 코드의 조각입니다 마지막 시도 버전으로 : 링크를 교체

private final static URL COMPUTEUSERPROFILEIMPLSERVICE_WSDL_LOCATION; 
private final static Logger logger = Logger.getLogger(com.xxxxx.xxxxx.xx.xxxxx.cup.ComputeUserProfileImplService.class.getName()); 

static { 
    URL url = null; 
    try { 
     URL baseUrl; 
     baseUrl = com.xxxxx.xxxxx.xx.xxxxx.xxx.ComputeUserProfileImplService.class.getResource(""); 
     url = new URL(baseUrl, "http://xxxx.xxxxx.ro:40000/idm/ws/cup?wsdl"); 

    } catch (MalformedURLException e) { 
     logger.warning("Failed to create URL for the wsdl Location: 'xxxxxxxxxxxxxxxx', retrying as a local file"); 
     logger.warning(e.getMessage()); 
    } 
    COMPUTEUSERPROFILEIMPLSERVICE_WSDL_LOCATION = url; 
} 

죄송합니다,하지만 난 권한이 없습니다 해요 :

Authenticator.setDefault(new Authenticator() { 
        @Override 
        protected PasswordAuthentication getPasswordAuthentication() { 
         return new PasswordAuthentication(
          username, 
          password.toCharArray()); 
        } 
       }); 


    ComputeUserProfileImplService computeUserProfileImplService = new ComputeUserProfileImplService(
    new URL(null, endpointURL, new sun.net.www.protocol.http.Handler()), 
    new QName("http://xxx.xx.xxxxx.xxxxx.com/", 
      "ComputeUserProfileImplService")); 
    ComputeUserProfileImpl computeUserProfile = computeUserProfileImplService 
    .getComputeUserProfileImplPort(); 

ComputeUserProfileImplService 코드의 모습 꽤 유명한 단체이기 때문에 게시하는 것이 좋습니다. 몇 가지 제안을 도와 주시면 감사하겠습니다. 나는 해결책을 찾고있다. 그러나 나는 붙어있다. 나는 그것을 이해할 수 없다. 그것은 나에게 적용되는이 weblogic 문제에 대한 해결 방법이되어야한다. 그러나 나는 그것을 찾을 수 없다. 필요한 경우 다른 스 니펫을 게시 해 드리겠습니다. 나는 이것으로 꽤 분명했기를 바랍니다.

미리 감사드립니다.

답변

4

불행히도 Weblogic은 다른 접근 방식을 가지고 있습니다. URLStreamHandler는 자체적으로 URLStreamHandler를 사용하여 인증을 무시합니다.

대신 내가 웹 로직에서 동일한 문제가 있었다

url = new URL(null, address, new sun.net.www.protocol.http.Handler()); // use Sun's handler 
2

나는 더 웹 로직에서 이것을 시도하지 않았지만, 톰캣, 글래스 피시, 아파치 Karaf, 기본 인증을 필요로 웹 서비스에 cliet 호출에 이것은 단지 좋은 작품 :

/** 
* Proxy. 
*/ 
private OperationsService proxy; 

/** 
* Operations wrapper constructor. 
* 
* @throws SystemException if error occurs 
*/ 
public OperationsWrapper() 
     throws SystemException { 
    try { 
     final String username = getBundle().getString("wswrappers.operations.username"); 
     final String password = getBundle().getString("wswrappers.operations.password"); 
     Authenticator.setDefault(new Authenticator() { 
      @Override 
      protected PasswordAuthentication getPasswordAuthentication() { 
       return new PasswordAuthentication(
         username, 
         password.toCharArray()); 
      } 
     }); 
     URL url = new URL(getBundle().getString("wswrappers.operations.url")); 
     QName qname = new QName("http://hltech.lt/ws/operations", "Operations"); 
     Service service = Service.create(url, qname); 
     proxy = service.getPort(OperationsService.class); 
     Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext(); 
     requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); 
     requestContext.put(BindingProvider.USERNAME_PROPERTY, username); 
     requestContext.put(BindingProvider.PASSWORD_PROPERTY, password); 
     Map<String, List<String>> headers = new HashMap<String, List<String>>(); 
     headers.put("Timeout", Collections.singletonList(getBundle().getString("wswrappers.operations.timeout"))); 
     requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers); 
    } catch (Exception e) { 
     LOGGER.error("Error occurred in operations web service client initialization", e); 
     throw new SystemException("Error occurred in operations web service client initialization", e); 
    } 
} 

내가 생각하지 않는 웹 로직 뭔가 다른 점이 있습니다. 이것은 효과가있다.

4

사용

url = new URL(address); // use WebLogic handler 

의 :

봅니다 썬의 구현을 사용합니다. 나는 Paulius Matulionis가 제시 한 솔루션은 웹 로직 (11)에 나를 위해 일한 당신을 위해 확인할 수 있습니다 웹 로직 스크립트 setDomainEnv에서

1) 변경 : 문제를 해결할 수

import my.MyPortType; 

import javax.xml.namespace.QName; 
import javax.xml.ws.BindingProvider; 
import javax.xml.ws.Service; 
import javax.xml.ws.handler.MessageContext; 
import java.net.Authenticator; 
import java.net.MalformedURLException; 
import java.net.PasswordAuthentication; 
import java.net.URL; 
import java.util.Collections; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

public class MyWebServiceClient { 

    public static void main(String[] args) { 
     URL url = null; 
     try { 
      url = new URL("http://host:10001/mycontext/ws?WSDL"); 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } 

     try { 
      final String username = "some"; 
      final String password = "other"; 
      Authenticator.setDefault(new Authenticator() { 
       @Override 
       protected PasswordAuthentication getPasswordAuthentication() { 
        return new PasswordAuthentication(
          username, 
          password.toCharArray()); 
       } 
      }); 
      QName qname = new QName("http://whatevertheqname/", "whatevertheservicename"); 
      Service service = Service.create(url, qname); 
      MyPortType proxy = service.getPort(MyPortType.class); 
      Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext(); 
      requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); 
      requestContext.put(BindingProvider.USERNAME_PROPERTY, username); 
      requestContext.put(BindingProvider.PASSWORD_PROPERTY, password); 
      Map<String, List<String>> headers = new HashMap<String, List<String>>(); 
      headers.put("Timeout", Collections.singletonList("10000")); 
      requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers); 
      String result = proxy.myMethod23"); 

      System.out.println("Result is: " + result); 

     } catch (Exception e) { 
      e.printStackTrace(); 
      throw new RuntimeException("Error occurred in operations web service client initialization", e); 
     } 


    } 
} 
0

다음은 제안. sh를 사용하여 WEBLOGIC에서 SunHttpHandler을 사용하도록합니다.

또는

2

) 쉘 스크립트/배치 파일을 사용하여 명령 프롬프트에서 웹 서비스를 호출합니다.

또는

3

는) 귀하의 웹 서비스 new URL(null, "http://...", new sun.net.www.protocol.http.Handler());

또는

4

) 자신의 태양 HTTP 처리기를 작성이 URL 객체를 사용해보십시오.

또는

5

) 거기에 새로 만든 웹 서비스를 추가하여 웹 로직-webservice.xml를 업데이트하십시오.

또는

6) JAX-RPC 대신 JAX-WS를 사용하여 시도.

처음 두 개 중 하나라도 문제를 해결할 수 있으면 좋겠지 만 다른 옵션도 유용합니다.

관련 문제